package com.zzyl.service.impl;

import com.zzyl.dto.BedDto;
import com.zzyl.entity.Bed;
import com.zzyl.mapper.BedMapper;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class BedServiceImpl implements BedService {

    @Autowired
    private BedMapper bedMapper;

    @Override
    public List<BedVo> getBedsByRoomId(Long roomId) {
        return bedMapper.getBedsByRoomId(roomId);
    }

    @Override
    public void create(BedDto bedDto) {
        Bed bed = new Bed();
        BeanUtils.copyProperties(bedDto,bed);
        bed.setBedStatus(0); //0为未入住
        bed.setCreateBy(1l);
        bed.setUpdateBy(1l);
        bed.setCreateTime(LocalDateTime.now());
        bed.setUpdateTime(LocalDateTime.now());
        bedMapper.create(bed);
    }

    @Override
    public BedVo readBedByBedId(Long id) {
        return bedMapper.readBedByBedId(id);
    }

    @Override
    public void updateBed(BedDto bedDto) {
        Bed bed = new Bed();
        BeanUtils.copyProperties(bedDto,bed);
        bed.setUpdateBy(1l);
        bed.setUpdateTime(LocalDateTime.now());
        bedMapper.updateBed(bed);
    }

    @Override
    public void deleteBed(Long id) {
        bedMapper.deleteBed(id);
    }
}

















